home *** CD-ROM | disk | FTP | other *** search
-
-
- CRITICAL ERROR HANDLER
- A WAY TO AVOID THE DREADED
- ABORT, RETRY, IGNORE, FAIL MESSAGE FROM WITHIN C PROGRAMS
-
-
- BY: PETER HYMAN
- 148 Tennyson Drive
- Plainsboro, NJ 08536
- (609) 799-2638
-
- JANUARY 1991
- with modifications 2/16/91
-
- PURPOSE: Some C Compilers offer a critical error trap, such as the former
- Lattice compiler. Others have no elegant way to do so, and if there is a
- critical error, you get the familiar Abort, Retry, Ignore, Fail message to
- mess up your screen display. CRITERR.ASM was designed to hook the INT 24H
- vector and allow for a graceful return from such an error while providing
- the programmer with complete information about the error.
-
- FILES: The following files are included.
-
- CETEST.C ; TEST C FILE TO DEMONSTRATE CRITERR USAGE
- CRITERR.ASM ; ASSEMBLER SOURCE FILE FOR ALTERNATE CRITICAL
- ; ERROR HANDLER
- CRITERR.H ; HEADER FILE CONTAINING STRUCTURE DEFINITIONS AND
- ; CHARACTER ARRAYS TO PRINT OUT ERRORS
- CRITERR.LST ; LISTING FILE FOR ASM MODULE
-
- COMPILATION STEPS: The assmebler file uses simplified segment directives
- and no separate macro include file. I have tested it with both the Microsoft
- and Turbo assemblers. Assemble with the following command line switches
-
- MSC: masm /mx /dI8086[s|c|m|l] criterr;
- TURBO: tasm /mx /dI8086[s|c|m|l] /q criterr
- The /q option will yield a much smaller object module
- The [s|c|m|l] are individual model designators, Small, Compact, Medium or
- Large.
-
- To compile the C test file, simply specify the memory model and other options
- you may want. I use the Zortech C++ compiler, and it requires no additional
- command line switches other than the memory or debug options.
-
- ztc -m[s|c|m|l] [-g] cetest [criterr.obj|criterr.asm]
-
- where [s|c|m|l] is the individual memory model, [-g] would be for the
- debugger, [criterr.obj] would be to link in the object module created for
- the alternate critical error handler, and/or [criterr.asm] would be if you
- wanted Zortech to call MASM for you (saving the step above).
-
- You may also want to add criterr to your library after testing.
-
- !!!!! THIS PROGRAM HAS NOT BEEN TESTED ON OS/2 OR WITH C++ !!!!!
-
- USAGE: There are two functions in the CRITERR.ASM module.
-
- CRITERR( ONOFF )
- CLRCRITERR( )
-
- int criterr( onoff )
- int onoff; 1 = turn on critical error trap, 0 = remove
-
- returns: 0 = installed, 1 = already installed
-
- if the handler has already been installed and you try to turn it on
- again, it will return a 1, otherwise, it will return a 0.
-
- void clrcriterr( void )
- fills structure with NULLs
-
- After DOS operations, the structure member cerr.ceflag will contain a 1 if
- there was a critical error. If not, check your compiler's system
- error variable (usually errno or oserr). If there was a critical error,
- complete diagnostic information is stored in the cerr structure (see
- criterr.h).
-
- If the error type was a disk error, the structure member cerr.drive will
- contain a character letter corresponding to the drive the error occured on
- (i.e. A,B,C ). If not, the error was probably a printer or other error, and
- you can read a device name for the character device header block in the
- structure member cerr.name. For DOS versions 3 and up, extended error
- information is also included in the structure members cerr.exterr, cerr.eclass,
- cerr.locus and cerr.action.
-
- Once the error type has been determined, several arrays of character strings
- can be referenced to get English translations of the error (see criterr.h).
-
- !!!!! IMPORTANT !!!!!
- THERE IS NO AUTOMATIC RESET OF THE CERR STRUCTURE. THE RESULTS ARE STICKY, AND
- UNLESS EXPLICITLY CLEARED, WILL REMAIN SET UNTIL THE NEXT CRITICAL ERROR.
- THEREFORE, THE FUNCTION clrcriterr() MUST BE CALLED AFTER THE ERROR HAS BEEN
- EVALUATED. IF CRITERR( 0 ) IS CALLED, THE STRUCTURE IS CLEARED.
-
- ALSO, THE LOGIC OF THIS HANDLER IS THAT IT WILL AUTOMATICALLY RETURN AN IGNORE
- OR FAIL CODE TO DOS TO RESTORE THE MACHINE TO A STABLE STATUS. THERE IS NO
- NEED TO PROMPT THE USER FOR ABORT, RETRY, ETC. YOU MAY SIMPLY SAY, PRINTER
- ERROR, OR DISK ERROR, CONTINUE?, OR PRINT THE ASSOCIATED ERROR MESSAGES IN
- CRITERR.H. IT'S MUCH CLEANER THIS WAY.
-
- Comments, Feedback? Please let me know your experience with this program and
- suggest any improvements, modification or corrections.
-
- You may wish to refer to a DOS Technical Reference Manual or other DOS Book
- for more information about how this handler works.
-
-
-
- 2/16/91:
-
- Several changes were made.
-
- The cerr structure was modified (see the criterr.h file). A new member
- ceflag was added to be used as a notification that a critical error
- occured. This was because a critical error number of 0 is used to
- indicate a write protect error. Rather than change the numbering to be 1
- indexed, I just set the flag.
-
- The external function _dos_exterr is no longer called. The reason is that
- the exterr is now byte length, and _dos_exterr expects a word. The
- program now calls int 59h directly.
-
- The code which set the read_wr member was moved. There was a bug which
- would leave it unset if a write error occured to a character device such
- as a printer. This would indicate a reading error, which is impossible.
- (see .asm source below the reponse: label).
-
- The method in which the program determined if the critical error handler
- was already installed was faulty. It never tested if it was already
- installed if you passed criterr(1). It would reinstall it and would cause
- you to lose the address of the original INT 24h handler. This means that
- the alternate handler would never be uninstalled until the C program was
- exited. See code below removetrap: and settrap: labels in the .asm
- source.
-
- Some small descriptive changes were made to the .h file. Also the cerr.
- structure was changed. Three new descriptive string arrays were added for
- showing Reading or Writing errors, Area of Disk in which an error occured,
- and for displaying allowable responses (see cetest.c).
-
- One additional note. The clrcriterr() function need not be called if you
- are just turning off the critical error handler. When you call criterr(0)
- if will clear the structure for you. It also initializes it when you turn
- it on. You only need to call clrcriterr() directly if the handler remains
- installed during program execution and a critical error has been observed.
-
- More feedback? I hope so.
-
-
- ----------------end-of-author's-documentation---------------
-
- Software Library Information:
-
- This disk copy provided as a service of
-
- Public (software) Library
-
- We are not the authors of this program, nor are we associated
- with the author in any way other than as a distributor of the
- program in accordance with the author's terms of distribution.
-
- Please direct shareware payments and specific questions about
- this program to the author of the program, whose name appears
- elsewhere in this documentation. If you have trouble getting
- in touch with the author, we will do whatever we can to help
- you with your questions. All programs have been tested and do
- run. To report problems, please use the form that is in the
- file PROBLEM.DOC on many of our disks or in other written for-
- mat with screen printouts, if possible. PsL cannot debug pro-
- programs over the telephone, though we can answer questions.
-
- Disks in the PsL are updated monthly, so if you did not get
- this disk directly from the PsL, you should be aware that the
- files in this set may no longer be the current versions. Also,
- if you got this disk from another vendor and are having prob-
- lems, be aware that some files may have become corrupted or
- lost by that vendor. Get a current, working disk from PsL.
-
- For a copy of the latest monthly software library newsletter
- and a list of the 3,000+ disks in the library, call or write
-
- Public (software) Library
- P.O.Box 35705 - F
- Houston, TX 77235-5705
-
- 1-800-2424-PSL
- MC/Visa/AmEx/Discover
-
- Outside of U.S. or in Texas
- or for general information,
- Call 1-713-524-6394
-
- PsL also has an outstanding
- catalog for the Macintosh.
-